clear all
program drop _all
set more off
set mem 600m

cd "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\kwan"
use "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\railway\cln_cty1931_railroad.dta"

replace county = 41060.5 if county==41061
merge m:m county using "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\kwan\pop1930_for_fishback.dta", nogenerate
drop if railroad==.

* Arizona
replace county = 4009 if county == 4011

* Louisiana
replace county = 22097 if county == 22039
replace county = 22019 if county == 22011 | county == 22003 | county == 22053

* New Mexico
replace county = 35017 if county == 35023
replace county = 35019 if county == 35011
replace county = 35005 if county == 35025

* Nevada
replace county = 32013 if county == 32027
replace county = 32009 if county == 32021

* Oklahoma
replace county = 40031 if county == 40033

* Oregon
replace county = 41013 if county == 41031 | county == 41017

* Texas
replace county = 48141 if county == 48229 | county == 48109
replace county = 48137 if county == 48385
replace county = 48355 if county == 48273 | county == 42849
replace county = 48061 if county == 48489
replace county = 48427 if county == 48407

* Utah
replace county = 49047 if county == 49009
replace county = 49051 if county == 49013

keep county railroad pop30

collapse (mean) railroad [weight=pop30] , by(county) 

replace railroad=2 if railroad>=1.5
replace railroad=1 if railroad>=0.5 & railroad<1.5
replace railroad=0 if railroad<0.5

gen major = (railroad==2)
gen minor = (railroad==1)

save railroad_clean.dta, replace

*****************************
*****************************
*****************************

clear all
program drop _all
set more off
set mem 600m

cd "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\kwan"
use "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\railway\cty_mex_distance.dta"

keep cty_fips miles_to_mex
rename cty_fips county
replace county = 41060.5 if county==41061

* Arizona
replace county = 4009 if county == 4011

* Louisiana
replace county = 22097 if county == 22039
replace county = 22019 if county == 22011 | county == 22003 | county == 22053

* New Mexico
replace county = 35017 if county == 35023
replace county = 35019 if county == 35011
replace county = 35005 if county == 35025

* Nevada
replace county = 32013 if county == 32027
replace county = 32009 if county == 32021

* Oklahoma
replace county = 40031 if county == 40033

* Oregon
replace county = 41013 if county == 41031 | county == 41017

* Texas
replace county = 48141 if county == 48229 | county == 48109
replace county = 48137 if county == 48385
replace county = 48355 if county == 48273 | county == 42849
replace county = 48061 if county == 48489
replace county = 48427 if county == 48407

* Utah
replace county = 49047 if county == 49009
replace county = 49051 if county == 49013

collapse (mean) miles_to_mex , by(county) 

save mex_distance_clean.dta, replace

*****************************
*****************************
*****************************

clear all
program drop _all
set more off
set mem 600m

cd "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\kwan"
use "C:\Users\master\Dropbox\Research\mexican_repatriates2\data\railway\cty_rr_distance.dta"

keep cty_fips miles_to_rr
rename cty_fips county
replace county = 41060.5 if county==41061

* Arizona
replace county = 4009 if county == 4011

* Louisiana
replace county = 22097 if county == 22039
replace county = 22019 if county == 22011 | county == 22003 | county == 22053

* New Mexico
replace county = 35017 if county == 35023
replace county = 35019 if county == 35011
replace county = 35005 if county == 35025

* Nevada
replace county = 32013 if county == 32027
replace county = 32009 if county == 32021

* Oklahoma
replace county = 40031 if county == 40033

* Oregon
replace county = 41013 if county == 41031 | county == 41017

* Texas
replace county = 48141 if county == 48229 | county == 48109
replace county = 48137 if county == 48385
replace county = 48355 if county == 48273 | county == 42849
replace county = 48061 if county == 48489
replace county = 48427 if county == 48407

* Utah
replace county = 49047 if county == 49009
replace county = 49051 if county == 49013

collapse (mean) miles_to_rr , by(county) 

save railroad_distance_clean.dta, replace



